#ifndef ELF_H
#define ELF_H

#include "types.h"

#define ELF_MAGIC 0x464C457FU //0x7f E L F

typedef struct elfhdr *elfHeaderPtr;
typedef struct proghdr *progHeaderPtr;
                              
// File header                
struct elfhdr 
{                          
  uint magic; // must equal ELF_MAGIC  
  uchar elf[12];                       
  ushort type;         /* Object file type */                       
  ushort machine;      /* Architecture */                  
  uint version;        /* Object file version */                    
  uint entry;          /* Entry point virtual address */                       
  uint phoff;          /* Program header table file offset, in bytes */                      
  uint shoff;          /* Section header table file offset, in bytes */                      
  uint flags;          /* Processor-specific flags. 0 for x86 */
  ushort ehsize;       /* ELF header size in bytes */                   
  ushort phentsize;    /* Program header table entry size */              
  ushort phnum;        /* Program header table entry count */                   
  ushort shentsize;    /* Section header table entry size */               
  ushort shnum;        /* Section header table entry count */                 
  ushort shstrndx;     /* Section header string table index */                 
};          



// Program header               
struct proghdr 
{
  uint type;     /* type of the segment decribed by this header */                      
  uint offset;   /* offset of this segment's first byte */
  uint va;       /* vitural address of this segment in memory */
  uint pa;       /* phisical address */                      
  uint filesz;   /* size in file */                      
  uint memsz;    /* size in memory */                      
  uint flags;    /* flags */                      
  uint align;    /* alignment info */                      
};                                      

// Values for Proghdr type              
#define ELF_PROG_LOAD           1       

// Flag  bits for Proghdr flags         
#define  ELF_PROG_FLAG_EXEC     1       
#define  ELF_PROG_FLAG_WRITE    2       
#define  ELF_PROG_FLAG_READ     4       

#endif
